<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<style>
  #app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
  }
</style>
</head>

<body>
  <div id="app">
    <h1>试试调整苏菲吧~</h1></h1>
    <h2>姓名:{{person.name}}--年龄:{{person.age}}--性别:{{person.sex}}--{{person.size}}</h2>
    <!-- 直接修改对象的属性是可以的 -->
    <button @click="changeAge">点击修改年龄为20</button><hr>
    <button @click="addSize">点击增加大小属性</button><hr>
    <button @click="changeName">点击修改苏菲的姓名</button><hr>
    <button @click="deleteSex">点击删除苏菲的性别</button>
  </div>
  <script>
    Vue.config.productionTip = false;
    //实例化Vue
    const vm = new Vue({
      el: "#app",
      data() {
        return {
          person:{
            name:"苏菲",
            age:18,
            sex:"女"
          }
        }
      },
      methods:{
        // 直接改变苏菲的年龄
        changeAge(){
          this.person.age=20
        },
        // 增大大小属性
        addSize(){
          // 不能直接添加
          // this.person.size="36D"
          Vue.set(this.person,"size","36D")
        },
        // 修改苏菲的姓名
        changeName(){
          Vue.set(this.person,"name","苏软软")
        }, 
        // 删除苏菲的姓名
        deleteSex(){
          Vue.delete(this.person,"name")
        }
      },
    })
  </script>
</body>

</html>